var plot1
$(document).ready(function(){
d=e;
bar_chart(e);

$('#chart1').bind('jqplotDataClick', 
    function (ev, seriesIndex, pointIndex, data) {
      $('#info2').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
    }
  ); 
})
function create_line(e,d,from,to,format)
{    
 plot1= $.jqplot('chart1', [e,d], {
      title:'Mail chart',
      series: [
        {label: 'Beans'},
        {label: 'Oranges'},],     
      axes:{
        xaxis:{                    
          renderer:$.jqplot.DateAxisRenderer,
          min: from?from:(new Date(2013, 0, 1)),
          max: to?to:(new Date(2013, 0, 7)),
          tickOptions:{
            formatString:format?format:'%b&nbsp;%#d',
            
          } 
        },
              
        yaxis:{
            max:7,
          tickOptions:{
            
            }
        }
      },
      highlighter: {
        show: true,
        sizeAdjust: 5.5
      },
      cursor: {
        show: false
      }
  });

}


function bar_chart(e,d,from,to,format)
{
    plot1= $.jqplot('chart1', [e,d], {
      
        stackSeries: true,
    captureRightClick: true,
    seriesDefaults:{
      renderer:$.jqplot.BarRenderer,
      rendererOptions: {
          // Put a 30 pixel margin between bars.
          barMargin: 5,
          barWidth:15,
          // Highlight bars when mouse button pressed.
          // Disables default highlighting on mouse over.
          highlightMouseDown: true   
      },
    },
      axes: {
      xaxis: {
          
           pad:2.5,
          renderer:$.jqplot.DateAxisRenderer,
          min: from?from:(new Date(2013, 0, 1)),
          max: to?to:(new Date(2013, 0, 7)),
      },
      yaxis: {
        // Don't pad out the bottom of the data range.  By default,
        // axes scaled as if data extended 10% above and below the
        // actual range to prevent data points right on grid boundaries.
        // Don't want to do that here.
        padMin: 0,
        max:20
        
      }
    },
    legend: {
      show: true,
      location: 'e',
      placement: 'outside'
    }   
       
  });
}



jQuery(document).ready(function()
{
  _init_control()

});
function draw()
{
    
}
function _init_control(){

jQuery('#_chart_fd').datetimebox({  
        showSeconds:false,
        mulitple: false,
        editable: false
    });
    jQuery('#_chart_td').datetimebox({  
        showSeconds:false,
        mulitple: false,
        editable: false
    });  
}

function _view_chart(type)
{
    jQuery.ajaxSetup( { "async": false });
    var from_date = $('#_chart_fd').datetimebox('getValue');
    var to_date = $('#_chart_td').datetimebox('getValue');
    if(from_date!=""&&to_date!="")
    {
        from_date=(new Date(from_date)).getTime()
        to_date=(new Date(to_date)).getTime()
    }
     if(type!=null)
     {
         url="/index.php?module=mailsystemmodule&action=chart_json&ajax_action=1&type=send&timeby="+type;
         jQuery.getJSON(url, function(data) {
             e=data;
            
         })
     }
      bar_chart(e,d,from_date,to_date,'%b&nbsp;%#d %H:00');
      plot1.redraw();
     /*
     plot1.data=e;
     plot1.axes.xaxis.min=from_date;
     plot1.axes.xaxis.max=to_date;
     plot1.redraw();*/
}



